# coding: utf-8

from django.shortcuts import render
from django.db.models import Q

from ddutils.views import BaseView
from jobs.models import TaskLog, Task, TaskHostLog, Category


class Dashboard(BaseView):

    template = 'base/dashboard.html'

    def get(self, request, *args, **kwargs):
        run_tasks_count = TaskLog.objects.exclude(status='SUCCESS').exclude(status='FAILURE').count()
        tasks_count = Task.objects.count()
        history_tasks_count = TaskLog.objects.filter(Q(status='SUCCESS')|Q(status='FAILURE')).count()
        hosts_count = TaskHostLog.objects.count()
        print run_tasks_count, tasks_count
        categories = Category.objects.all()
        return render(request, self.template, {'run_tasks_count': run_tasks_count,
                                               'tasks_count': tasks_count, 'hosts_count': hosts_count,
                                               'history_tasks_count': history_tasks_count, 'categories': categories})
